<!--
 * @Descripttion: 
 * @version: 1.0.0
 * @Author: guoxiaomin
 * @Email: 1093556028@qq.com
 * @Date: 2019-08-21 11:10:05
 * @LastEditors: guoxiaomin
 * @LastEditTime: 2019-09-12 10:28:20
 -->
//  <style lang="less">
//  .lineInput{
//    /deep/ #nameInput, #phoneInput{
//     background: #EEEEEE;
//   }
//  }
  
//  </style>
 
<style lang="less" scoped>
.form{
  width:5.61rem;
  height:6.15rem;
  background: rgba(255, 255, 255, 1);
  border-radius: 0.1rem;
  box-sizing: border-box;
  padding: 1.21rem 0.47rem 0 0.55rem;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  .close{
    color:#000000;
    font-size: 0.3rem;
    position: absolute;
    right: 0.47rem;
    top: 0.36rem;
  }
  .lineInput{
    background: #EEEEEE;
    border-radius: 0.1rem;
    display: flex;
    align-items: center;
    padding-left: 0.25rem;
    box-sizing: border-box;
    .icon{
      width: 0.28rem;
      height: 0.28rem;
    }
    .nameIcon{
      width: 0.24rem;
    }
  }
  .phoneInput{
    margin-top: 0.43rem;
  }
  .getTip{
    color: #999999;
    font-size: 0.22rem;
    text-align: center;
    padding-top: 0.18rem;
  }
  .info{
    margin-top: 0.55rem;
    line-height: 0.24rem;
    text-align: center;
    .txt1{
      color: #000000;
      font-size: 0.18rem;
    }
    .txt2{
      color: #333333;
      font-size: 0.32rem;
      font-weight: bold;
      margin-left: 0.15rem;
      letter-spacing: 0.02rem;
    }
  }
  .getBtn{
    width:4.59rem;
    height:0.8rem;
    background:rgba(253,55,26,1);
    border-radius:0.03rem;
    font-size: 0.32rem;
    color: #ffffff;
    text-align: center;
    line-height: 0.8rem;
    margin-top: 0.31rem;
    cursor: pointer;
  }
}
</style>
<template>
  <div class="form" v-if="isShow" @touchmove.prevent>
    <p class="close" @click="closeLogin">关闭</p>
    <div class='nameInput lineInput'>
      <img src="../assets/web/iconWd@2x.png" alt="" class="icon nameIcon">
      <input-verify
        class='realInput'
        inputColor='#EEEEEE'
        type="text"
        autocomplete="off"
        ref="nameInput"
        labelFor="nameInput"
        placeholder="请输入姓名"
        :rules='name'
        :doNotShowSuccess='true'
        @change="handleNameChange"
      />
    </div>
    <div class='phoneInput lineInput'>
      <img src="../assets/web/iconDh@2x.png" alt="" class="icon phoneIcon">
      <input-verify
        inputColor='#EEEEEE'
        class='realInput'
        type="tel"
        autocomplete="off"
        ref="phoneInput"
        labelFor="phoneInput"
        placeholder="请输入手机号"
        :rules='phone'
        :doNotShowSuccess='true'
        @change="handlePhoneChange"
      />
    </div>
    <div class="getTip" v-if="isShowTip">您已申请成功，我们将尽快联系您!</div>
    <p class="info">
      <span class="txt1">公司热线</span>
      <span class="txt2">010-87506918</span>
    </p>
    <div class="getBtn" @click="askForMoneyClicked">极速申请</div>
  </div>
</template>
<script>
import InputVerify from './InputVerify'
import Toast from '../common/toast'
export default {
  props: {
    isShow: {
      type: Boolean,
      default: false
    }
  },
  components: {
    InputVerify
  },
  data() {
    return {
      userName: '',
      userPhone: '',
      isShowTip: false,
      phone: [
        { required: true, msg: '手机号不能为空' },
        {
          msg: '手机号格式不正确',
          partern: /^1((3\d)|(4(5|7))|([5-9]\d))\d{8}$/
        }
      ],
      name: [
        { required: true, msg: '验证码不能为空' }
      ]
    }
  },
   methods: {
    handlePhoneChange (e) {
      this.userPhone = e
    },
    handleNameChange (e) {
      this.userName = e
    },
    closeLogin() {
      this.$emit('closeLogin')
    },
    // 申请贷款
    askForMoneyClicked() {
      const situation1st = this.$refs.phoneInput._validate()
      const situation2st = this.$refs.nameInput._validate()
      if (!situation1st || !situation2st) {
        return
      }
      this.$service.post('http://api.dingwealth.com/users/add',{
        userName: this.userName,
        phone: this.userPhone
      }).then(() => {
        this.isShowTip = true
        Toast({
          text: '申请成功，稍后会有工作人员联系您！'
        })
      })
    }
  }
}
</script>